Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

you can pass me the bonus one #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anaaristow
Copy link

No description provided.

@sh-ih
Copy link

sh-ih commented Oct 16, 2023

Ana,

Great job on this lab!

It is always a good idea to test our own functions, but your tests on questions 2,3,5 and 7 gave you errors because the functions were created to get lists as arguments and you weren’t passing your arguments as lists.

For instance, in question 2, you ran:
greatest(2,3,4,2) #you are missing the square brackets used to define a list on Python
Instead of greatest([2,3,4,2])

On question 3, it should be sum_all([4,9,8,20])

On question 4: mult_all([9,2,6,7[)

On question 5, your function had two arguments: a list and a string that could be either “+” or “*”. You ran:
oper_all[9,2,4,5],("*")
Instead of
oper_all([9,2,4,5],"*") # [9,2,4,5] is a list and “*” is a string and both arguments need to be inside the parenthesis ( )

In that same question, you need to delete the asterisk before arr for the function to work properly and pass the test.

On question 7, it should be: unique([2,2,2,5])

About the bonus questions, a possible solution to question 11 would be to create a dictionary were the keys are the words of your list and the values are the frequency of each word. Then, you just look for the highest value:

def mode_counter(arr):
    dict_arr = {}
    for element in arr:
        dict_arr[element]=0
    for element in arr:
        index = [i for i,e in enumerate(arr) if e == element]
        dict_arr[element]=len(index)
    max_count = max(dict_arr, key=dict_arr.get)
    return max_count

For question 12:

def sort_alpha(input_string):
    # Initialize an empty list to store the words
    words = []

    # Initialize variables to keep track of the current word
    current_word = ""
    is_inside_word = False

    # Iterate through each character in the input string
    for char in input_string:
        if char == ',':
            # If a comma is encountered, append the current word to the list
            if is_inside_word:
                words.append(current_word)
                current_word = ""
                is_inside_word = False
        else:
            # Add the character to the current word
            current_word += char
            is_inside_word = True

    # If there's a word left after the loop, append it to the list
    if is_inside_word:
        words.append(current_word)

    # Sort the list of words alphabetically
    words.sort()

    # Create a sorted string by joining the sorted words with commas
    sorted_string = ""
    for word in words:
        sorted_string += word + ","

    return sorted_string[:-1]

Please let me know if you have any questions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants